

$('#file').on('change',function(){
    var formData=new FormData();
    formData.append('image',this.files[0]);
    $.ajax({
        type:'post',
        url:'/upload',
        data:formData,
        processData:false,
        contentType:false,
        success:function(res){
            console.log(res);
            $('#image').val(res[0].image);
        }

    })
});


$('#slides').on('submit',function(){
    var formData=$(this).serialize();
    $.ajax({
        type:'post',
        url:'/slides',
        data:formData,
        success:function(){
            location.reload();
        }
    })
})

$.ajax({
    type:'get',
    url:'/slides',
    success:function(res){
        var html=template('showTpl',{data:res});
        $('#slideshow').html(html);
    }
});

$('#slideshow').on('click','.delete',function(){
    var id=$(this).attr('data-id');
    $.ajax({
        type:'delete',
        url:'/slides/'+id,
        success:function(){
            location.reload();
        }
    })
})
